﻿using System;
using System.Text;
using System.Text.RegularExpressions;
using System.Xml;

namespace WeiSha.Core
{
	// Token: 0x0200000A RID: 10
	public static class XmlDocumentHelper
	{
		// Token: 0x06000042 RID: 66 RVA: 0x000036B0 File Offset: 0x000018B0
		public static void LoadXml(this XmlDocument doc, string xml, bool isDtd)
		{
			xml = XmlDocumentHelper.ReplaceLowOrderASCIICharacters(xml);
			bool flag = !isDtd;
			if (flag)
			{
				Regex regex = new Regex("<!DOCTYPE|<!ENTITY", RegexOptions.IgnoreCase | RegexOptions.Multiline);
				bool flag2 = regex.IsMatch(xml);
				if (flag2)
				{
					throw new Exception("禁止使用DTD定义！请移除DOCTYPE或ENTITY标签。");
				}
			}
			doc.LoadXml(xml);
		}

		// Token: 0x06000043 RID: 67 RVA: 0x000036FC File Offset: 0x000018FC
		public static string ReplaceLowOrderASCIICharacters(string text)
		{
			StringBuilder stringBuilder = new StringBuilder();
			foreach (char c in text)
			{
				int num = (int)c;
				bool flag = (num >= 0 && num <= 8) || (num >= 11 && num <= 12) || (num >= 14 && num <= 32);
				if (flag)
				{
					stringBuilder.AppendFormat(" ", num);
				}
				else
				{
					stringBuilder.Append(c);
				}
			}
			return stringBuilder.ToString();
		}
	}
}
